#include "libcomm.h"
#if (COMM_FEATURE_LIBEVENT==1)


MessageFilterManager::MessageFilterManager(List<MessageFilter*>* filterList) 
	: m_filterList(filterList)
{
}

MessageFilterManager::~MessageFilterManager()
{
}

void MessageFilterManager::OnOpen()
{
	stdlist<MessageFilter*> filterList = m_filterList->list();
	foreach(MessageFilter*,filter,filterList)
	{
		filter->OnOpen(this);
	}
}

// reason: CONN_EOF(peer shutdown),CONN_ERR(connection error),CONN_SHUTDOWN(close by manual).
void MessageFilterManager::OnClose(SocketClient::ConnectionState reason)
{
	stdlist<MessageFilter*> filterList = m_filterList->list();
	foreach(MessageFilter*,filter,filterList)
	{
		filter->OnClose(this,reason);
	}
}

void MessageFilterManager::OnMessage(const char* buffer, int size)
{
	stdlist<MessageFilter*> filterList = m_filterList->list();
	foreach(MessageFilter*,filter,filterList)
	{
		if(filter->OnMessage(this,buffer,size))
			break;
	}
}


#endif